﻿@model OrgViewModel


<section class="content-header">
    <h1>
        <a href="javascript:window.app.loadUI('@Url.Action("Create")')">编辑VIU</a>
    </h1>
    <ol class="breadcrumb">
        <li><a href="@Url.Action("Index", "Home")"><i class="fa fa-home"></i> 首页</a></li>
        <li class="">组织结构</li>
        <li class="active">组织结构管理</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-body">
                    <div id="modalcontent">
                        @using (Html.Bootstrap().BeginForm(c => c.Horizontal()))
                        {
                            @Html.ValidationSummary()
                            <div class="form-group">
                                @Html.LabelFor(m => m.Title, new { @class = "col-sm-2 control-label" })
                                <div class="col-sm-10">
                                    @Html.Bootstrap().TextBoxFor(m => m.Title)
                                </div>
                            </div>
                            <div class="form-group">
                                @Html.LabelFor(m => m.Code, new { @class = "col-sm-2 control-label" })
                                <div class="col-sm-10">
                                    @Html.Bootstrap().TextBoxFor(m => m.Code)
                                </div>
                            </div>
                            <div class="form-group">
                                @Html.LabelFor(m => m.ParentId, new { @class = "col-sm-2 control-label" })
                                <div class="col-sm-10">
                                    <input id="orgSel" class="form-control" type="text" value="@Model.ParentText" onfocus="showMenu(this);" />
                                    @Html.HiddenFor(m => m.ParentId)
                                    <div id="ParentmenuContent" class="menuContent" style="display: none; position: absolute; display: none; left: 15px; top: 33px; z-index: 1000;">
                                        <ul id="Parentdropdownmenu" class="ztree" style="margin-top: 0; width: 260px;"></ul>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                @Html.LabelFor(m => m.Remark, new { @class = "col-sm-2 control-label" })
                                <div class="col-sm-10">
                                    @Html.Bootstrap().TextareaFor(m => m.Remark)
                                </div>
                            </div>
                            @Html.HiddenFor(x => x.Id)
                        }
                    </div>

                </div>
                <div class="box-footer text-center box-outfooter">
                    @Html.Bootstrap().Button("保存").Style(BootstrapStyle.Primary).Click("SaveForm(event,'" + @Url.Action("Save") + "');")
                    @Html.Bootstrap().Button("返回").Style(BootstrapStyle.Default).Click("window.app.loadUI('" + Url.Action("Index") + "');")
                </div>
            </div>
        </div>
    </div>

</section>

<script type="text/javascript">

    var data = @MvcHtmlString.Create(Model.TreeNodes.ToJson());
    var zNodes = data.children;

    function showMenu(treeSel) {
        $("#ParentmenuContent")
            .slideDown("fast");

        $("body").bind("mousedown", onBodyDown);
    }
    function hideMenu() {
        $("#ParentmenuContent").fadeOut("fast");
        $("body").unbind("mousedown", onBodyDown);
    }
    function onBodyDown(event) {
        if (!(event.target.id === "menuBtn" || event.target.id === "ParentmenuContent" || $(event.target).parents("#ParentmenuContent").length>0)) {
            hideMenu();
        }
    }

    $(document).ready(function(){
        $.fn.zTree.init($("#Parentdropdownmenu"), {
            view: { dblClickExpand: false },
            data: { simpleData: { enable: true } },
            callback: {
                onClick: function (e, treeId, treeNode) {
                    $("#orgSel").attr("value", treeNode.name);
                    $("#ParentId").val(treeNode.id);
                }
            }
        }, zNodes);

        var treeObj = $.fn.zTree.getZTreeObj("Parentdropdownmenu");
        var node = treeObj.getNodeByParam("id", '@Model.ParentId', null);
        if(node)
            treeObj.selectNode(node);
    });
</script>
